﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jargon.Resources;

namespace Jargon.Web.Controls
{
    /// <summary>
    /// Standard ASP.NET <see cref="System.Web.UI.WebControls.Button"/> with Jargon capabilities
    /// </summary>
    [DefaultProperty("JargonKey")]
    [ToolboxData("<{0}:JargonButton runat=server></{0}:JargonButton>")]
    public class JargonButton : Button
    {
        /// <summary>
        /// Gets or sets the key of the text to display in Jargon
        /// </summary>
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string JargonKey
        {
            get
            {
                String s = (String)ViewState["JargonKey"];
                return ((s == null) ? String.Empty : s);
            }

            set
            {
                ViewState["JargonKey"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the lettercase to acquire the Jargon text
        /// </summary>
        public JargonLetterCase LetterCase
        {
            get
            {
                JargonLetterCase letterCase = JargonLetterCase.Standard;
                if (ViewState["LetterCase"] != null)
                {
                    letterCase = (JargonLetterCase)ViewState["LetterCase"];
                }
                return letterCase;
            }
            set
            {
                ViewState["LetterCase"] = value;
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.Text = JargonTextReader.GetString(JargonKey, LetterCase);
        }

        protected override void RenderContents(HtmlTextWriter output)
        {
            base.RenderContents(output);
        }
    }
}
